from tqdm import tqdm

file = open("attachment.txt",'r')
flag = open("flag.txt",'w')
linee = file.readlines()

num = []
string = ""

# 添加 tqdm 进度条来跟踪行的处理进度
for i in tqdm(linee, desc="Processing lines"):
    num.append("".join(i.split('\n')))

# 添加 tqdm 进度条来跟踪数字到二进制的转换进度
for n in tqdm(num, desc="Converting to binary"):
    if(n == '63'):
        n = '00'
    if(n == '127'):
        n = '01'
    if(n == '191'):
        n = '10'        
    if(n == '255'):
        n = '11'
    string += n

step = 8
b = [string[i:i+step] for i in range(0,len(string),step)]
hey = []

# 添加 tqdm 进度条来跟踪分块后的处理
for i in tqdm(b, desc="Handling chunks"):
    hey.append(i)

# 添加 tqdm 进度条来跟踪字符写入文件的进度
for i in tqdm(hey, desc="Writing to flag.txt"):
    flag.write(chr(int(i,2)))

# 关闭文件
file.close()
flag.close()
